<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>网站配置 - bootstrap中文后台管理系统模板</title>
    <link href="/static/admin/css/bootstrap.min.css" rel="stylesheet">
    <link href="/static/admin/css/fonts.css" rel="stylesheet">
    <link href="/static/admin/css/style.css" rel="stylesheet">
</head>

<body>
<!--页面主要内容-->
<main class="ftdms-layout-content">
    <div class="container-fluid" style="margin-bottom:90px;">
        <div class="row" style="margin-top:15px;">
            <div class="col-lg-12">
                <div class="card">
                    <ul class="nav nav-tabs page-tabs">
                        <li><a href="/admin/link">新增友情连接</a></li>
                        <li class="active"><a href="javascript:void(0)">查看管理</a></li>
                    </ul>
                    <div class="tab-content">
                        <div class="tab-pane active">
                            <div class="table-responsive">
                                <table class="table table-hover">
                                    <thead>
                                    <tr>
                                        <th>
                                            <label class="ftdms-checkbox checkbox-primary">
                                                <input type="checkbox" id="delsheader"><span>删除</span>
                                            </label>
                                        </th>
                                        <th>#</th>
                                        <th>标题文本</th>
                                        <th>网址</th>
                                        <th>是否显示</th>
                                        <th>操作</th>
                                    </tr>
                                    </thead>
                                    <tbody>
                                    <#list links as link>
                                        <tr>
                                            <td><label class="ftdms-checkbox checkbox-primary">
                                                    <input type="checkbox" name="dels" value="${link.id}"><span></span>
                                                </label></td>
                                            <td>${link.id}</td>
                                            <td>${link.title}</td>
                                            <td>${link.url}</td>
                                            <td>
                                                <label class="ftdms-switch switch-solid switch-primary">
                                                    <input type="checkbox" name="shows" did="${link.id}"
                                                           value="${link.shows?string("1","0")}" ${link.shows?string("checked","")}>
                                                    <span></span>
                                                </label>
                                            </td>
                                            <td><a href="javascript:void(0)" delid="${link.id}"
                                                   class="btn del btn-xs btn-danger">删除</a></td>
                                        </tr>
                                    <#else>
                                        <tr>
                                            <td colspan="100">无数据</td>
                                        </tr>
                                    </#list>

                                    <tr>
                                        <td colspan="100">
                                            ${pageinfo}
                                        </td>
                                    </tr>
                                    </tbody>
                                </table>
                                <a href="javascript:void(0)" class="btn delall btn-xs btn-danger">删除所选</a>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</main>
<!--End 页面主要内容-->
<script src="/static/admin/js/jquery.min.js"></script>
<script>
    $(function () {
        $("#delsheader").click(function () {
            if ($(this).is(':checked')) {
                $("input:checkbox[name=dels]").prop("checked", true);
            } else {
                $("input:checkbox[name=dels]").prop("checked", false);
            }
        });


        //删除所选
        $('.delall').click(function () {
            let arr = [];
            let i = 0;
            $("input:checked[name=dels]").each(function (a, b) {
                arr[i++] = $(b).val();
            });

            if (arr.length > 0) {


                $.ajax({
                    type: 'POST',
                    url: '/admin/link',
                    data: {ids: arr.join(","), action: "delall"},
                    success: function (e) {

                    }
                });

            } else {
                alert("请选择");
            }

        });

        /*
        $('tbody tr').click(function(){
          let t = $(this);
          let c = t.find(':checkbox');
          c.prop("checked",!c.prop("checked"));
        });

         */

        //删除一个
        $(".del").click(function () {
            let t = $(this);
            $.ajax({
                type: 'POST',
                url: '/admin/link',
                data: {id: t.attr('delid'), action: "delbyid"},
                success: function (e) {
                    t.parent().parent().remove();
                }
            });
        });

        //设置显示和隐藏
        $(':checkbox[name=shows]').click(function () {
            let t = $(this);
            $.ajax({
                type: 'POST',
                url: '/admin/link',
                data: {id: t.attr('did'), shows: t.val() == 0 ? true : false, action: "shows"},
                success: function (e) {
                    //location.reload();
                    t.val(t.val() == 0 ? 1 : 0);
                }
            });
        });
    });
</script>
</body>
</html>